using System;

public static class Program {
   public static void Main() {
      StackallocDemo();
      InlineArrayDemo();
   }

   private static void StackallocDemo() {
      unsafe {
         const Int32 width = 20;
         Char* pc = stackalloc Char[width];	// Allocates array on stack
      
         String s = "Jeffrey Richter";	// 15 characters
         
         for (Int32 index = 0; index < width; index++) {
            pc[width - index - 1] =
               (index < s.Length) ? s[index] : '.';
         }
         Console.WriteLine(new String(pc, 0, width));	// ".....rethciR yerffeJ"
      }
   }

   private static void InlineArrayDemo() {
      unsafe {
         CharArray ca;	// Allocates array on stack
         Int32 widthInBytes = sizeof(CharArray);
         Int32 width = widthInBytes / 2;

         String s = "Jeffrey Richter";	// 15 characters

         for (Int32 index = 0; index < width; index++) {
            ca.Characters[width - index - 1] =
               (index < s.Length) ? s[index] : '.';
         }
         Console.WriteLine(new String(ca.Characters, 0, width));	// ".....rethciR yerffeJ"
      }
   }
}

internal unsafe struct CharArray {
   // This array is embedded inline inside the structure
   public fixed Char Characters[20];
}